<?php
require_once ("BaseController.php");
require_once ("db/facade/ReadFacade.php");
require_once ("components/ProductPager.php");

class ProductController extends BaseController {

	public function ulozProdukt($produkt) {
		//delegace pro DAO tridu

		echo ("Produkt s nazvem " . $produkt->getNazev() . " byl ulozen do databaze");

	}

	public function createProductPager($idCategory, $curPage, $config) {

		$data = null;
		$celkovyPocet = ReadFacade :: getInstance()->getProductCount($idCategory);

		if ($celkovyPocet > 0) {
				$pokolika = $config['counter'];
				
				$bottom = $curPage * $pokolika;
				$top = $pokolika;
				
				if($bottom > $celkovyPocet) {
					//bottom pocita se spravnou hodnotou page parametru
					Utils::sendError("errorPage.php","uzivatel je filuta (nesmyslny page parametr)");
				}
			
				$data = ReadFacade :: getInstance()->loadProductListByCategoryLimit($idCategory, $bottom, $top);
			
				$pager = new ProductPager($data, $curPage, $celkovyPocet, $config);
			}
			 else {
			echo "Nenalezeny zadne zaznamy s id <b>" . $idCategory . "</b>";
		}

	}

}